public-obj-c=$(wildcard ./src/*.c)
public-obj-o=$(patsubst %.c, %.o, $(public-obj-c))

login-obj-c=$(wildcard ./login/*.c)
login-obj-o=$(patsubst %.c, %.o, $(login-obj-c))

getuserinfo-obj-c=$(wildcard ./getuserinfo/*.c)
getuserinfo-obj-o=$(patsubst %.c, %.o, $(getuserinfo-obj-c))

logout-obj-c=$(wildcard ./loginout/*.c)
logout-obj-o=$(patsubst %.c, %.o, $(logout-obj-c))

led-obj-c=$(wildcard ./led/*.c)
led-obj-o=$(patsubst %.c, %.o, $(led-obj-c))

humidity-obj-c=$(wildcard ./humidity/*.c)
humidity-obj-o=$(patsubst %.c, %.o, $(humidity-obj-c))

fan-obj-c=$(wildcard ./fan/*.c)
fan-obj-o=$(patsubst %.c, %.o, $(fan-obj-c))

smog-obj-c=$(wildcard ./smog/*.c)
smog-obj-o=$(patsubst %.c, %.o, $(smog-obj-c))

temp-obj-c=$(wildcard ./temp/*.c)
temp-obj-o=$(patsubst %.c, %.o, $(temp-obj-c))

getsysinfo-obj-c=$(wildcard ./getsysinfo/*.c)
getsysinfo-obj-o=$(patsubst %.c, %.o, $(getsysinfo-obj-c))

intensity-obj-c=$(wildcard ./intensity/*.c)
intensity-obj-o=$(patsubst %.c, %.o, $(intensity-obj-c))

curtain-obj-c=$(wildcard ./curtain/*.c)
curtain-obj-o=$(patsubst %.c, %.o, $(curtain-obj-c))

beep-obj-c=$(wildcard ./beep/*.c)
beep-obj-o=$(patsubst %.c, %.o, $(beep-obj-c))

door-obj-c=$(wildcard ./door/*.c)
door-obj-o=$(patsubst %.c, %.o, $(door-obj-c))

test-obj-c=$(wildcard ./test/*.c)
test-obj-o=$(patsubst %.c, %.o, $(test-obj-c))

getlist-obj-c=$(wildcard ./getlist/*.c)
getlist-obj-o=$(patsubst %.c, %.o, $(getlist-obj-c))

setdevcfg-obj-c=$(wildcard ./setdevcfg/*.c)
setdevcfg-obj-o=$(patsubst %.c, %.o, $(setdevcfg-obj-c))

getdevcfg-obj-c=$(wildcard ./getdevcfg/*.c)
getdevcfg-obj-o=$(patsubst %.c, %.o, $(getdevcfg-obj-c))

setsensorcfg-obj-c=$(wildcard ./setsensorcfg/*.c)
setsensorcfg-obj-o=$(patsubst %.c, %.o, $(setsensorcfg-obj-c))

getsensorinfo-obj-c=$(wildcard ./getsensorinfo/*.c)
getsensorinfo-obj-o=$(patsubst %.c, %.o, $(getsensorinfo-obj-c))

delnode-obj-c=$(wildcard ./delnode/*.c)
delnode-obj-o=$(patsubst %.c, %.o, $(delnode-obj-c))

deltiming-obj-c=$(wildcard ./deltiming/*.c)
deltiming-obj-o=$(patsubst %.c, %.o, $(deltiming-obj-c))

addtiming-obj-c=$(wildcard ./addtiming/*.c)
addtiming-obj-o=$(patsubst %.c, %.o, $(addtiming-obj-c))

gettiminglist-obj-c=$(wildcard ./gettiminglist/*.c)
gettiminglist-obj-o=$(patsubst %.c, %.o, $(gettiminglist-obj-c))

updatetiming-obj-c=$(wildcard ./updatetiming/*.c)
updatetiming-obj-o=$(patsubst %.c, %.o, $(updatetiming-obj-c))

phone_cfg-obj-c=$(wildcard ./phone_cfg/*.c)
phone_cfg-obj-o=$(patsubst %.c, %.o, $(phone_cfg-obj-c))

all-obj = $(login-obj-o) $(getuserinfo-obj-o) $(logout-obj-o) $(led-obj-o) $(humidity-obj-o) $(fan-obj-o) $(smog-obj-o) $(temp-obj-o) $(getsysinfo-obj-o) $(intensity-obj-o) $(curtain-obj-o) $(beep-obj-o) $(door-obj-o) $(test-obj-o) $(getlist-obj-o) $(setdevcfg-obj-o) $(getdevcfg-obj-o) $(setsensorcfg-obj-o) $(getsensorinfo-obj-o) $(deltiming-obj-o) $(addtiming-obj-o) $(gettiminglist-obj-o) $(updatetiming-obj-o) $(phone_cfg-obj-o)

CFLAGS=-g -Wall -I ./include
CC=arm-none-linux-gnueabi-gcc
LIBS=-lpthread -L ./lib -lsqlite3 -lcgic

all: login.cgi logout.cgi getuserinfo.cgi ledc.cgi humidity.cgi fanc.cgi smog.cgi temp.cgi getsysinfo.cgi intensity.cgi curtain.cgi beep.cgi door.cgi test.cgi getlist.cgi setdevcfg.cgi getdevcfg.cgi setsensorcfg.cgi getsensorinfo.cgi delnode.cgi deltiming.cgi addtiming.cgi gettiminglist.cgi updatetiming.cgi phone_cfg.cgi

#mingw32 and cygwin users: replace .cgi with .exe

$(obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(login-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(getuserinfo-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 

$(logout-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 

$(led-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(humidity-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 	
	
$(fan-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(smog-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(temp-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(getsysinfo-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(intensity-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(curtain-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(beep-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(door-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(test-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(getlist-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(setdevcfg-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS) 
	
$(getdevcfg-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(setsensorcfg-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(getsensorinfo-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(delnode-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(deltiming-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(addtiming-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(gettiminglist-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)
	
$(updatetiming-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)

$(phone_cfg-obj-o):%.o:%.c
	$(CC) -c $< -o $@ $(LDFLAGS) $(CFLAGS)

login.cgi: $(login-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(login-obj-o) $(public-obj-o) -o login.cgi ${LIBS}

logout.cgi: $(logout-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(logout-obj-o) $(public-obj-o) -o logout.cgi ${LIBS}

getuserinfo.cgi: $(getuserinfo-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(getuserinfo-obj-o) $(public-obj-o) -o getuserinfo.cgi ${LIBS}
	
ledc.cgi: $(led-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(led-obj-o) $(public-obj-o) -o ledc.cgi ${LIBS}
	
humidity.cgi: $(humidity-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(humidity-obj-o) $(public-obj-o) -o humidity.cgi ${LIBS}
	
fanc.cgi: $(fan-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(fan-obj-o) $(public-obj-o) -o fanc.cgi ${LIBS}
	
smog.cgi: $(smog-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(smog-obj-o) $(public-obj-o) -o smog.cgi ${LIBS}
	
temp.cgi: $(temp-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(temp-obj-o) $(public-obj-o) -o temp.cgi ${LIBS}
	
getsysinfo.cgi: $(getsysinfo-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(getsysinfo-obj-o) $(public-obj-o) -o getsysinfo.cgi ${LIBS}
	
intensity.cgi: $(intensity-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(intensity-obj-o) $(public-obj-o) -o intensity.cgi ${LIBS}
	
curtain.cgi: $(curtain-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(curtain-obj-o) $(public-obj-o) -o curtain.cgi ${LIBS}
	
beep.cgi: $(beep-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(beep-obj-o) $(public-obj-o) -o beep.cgi ${LIBS}
	
door.cgi: $(door-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(door-obj-o) $(public-obj-o) -o door.cgi ${LIBS}
	
test.cgi: $(test-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(test-obj-o) $(public-obj-o) -o test.cgi ${LIBS}
	
getlist.cgi: $(getlist-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(getlist-obj-o) $(public-obj-o) -o getlist.cgi ${LIBS}
	
setdevcfg.cgi: $(setdevcfg-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(setdevcfg-obj-o) $(public-obj-o) -o setdevcfg.cgi ${LIBS}
	
getdevcfg.cgi: $(getdevcfg-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(getdevcfg-obj-o) $(public-obj-o) -o getdevcfg.cgi ${LIBS}
	
setsensorcfg.cgi: $(setsensorcfg-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(setsensorcfg-obj-o) $(public-obj-o) -o setsensorcfg.cgi ${LIBS}
	
getsensorinfo.cgi: $(getsensorinfo-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(getsensorinfo-obj-o) $(public-obj-o) -o getsensorinfo.cgi ${LIBS}
	
delnode.cgi: $(delnode-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(delnode-obj-o) $(public-obj-o) -o delnode.cgi ${LIBS}
	
deltiming.cgi: $(deltiming-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(deltiming-obj-o) $(public-obj-o) -o deltiming.cgi ${LIBS}
	
addtiming.cgi: $(addtiming-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(addtiming-obj-o) $(public-obj-o) -o addtiming.cgi ${LIBS}
	
gettiminglist.cgi: $(gettiminglist-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(gettiminglist-obj-o) $(public-obj-o) -o gettiminglist.cgi ${LIBS}
	
updatetiming.cgi: $(updatetiming-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(updatetiming-obj-o) $(public-obj-o) -o updatetiming.cgi ${LIBS}
	
phone_cfg.cgi: $(phone_cfg-obj-o) $(public-obj-o)
	$(CC) $(CFLAGS) $(phone_cfg-obj-o) $(public-obj-o) -o phone_cfg.cgi ${LIBS}
	
clean:
	rm -f *.cgi $(all-obj)
